public class Work05 {
    private static int[] nums = {1, 2, 3, 4, 5, 6, 7}; //全排列可能要用到的数字


    public static void main(String[] args) {

        //不要求保证输出顺序 手写全排列
        dfs(0, 2);  //1 2 3 的全排列

    }

    private static void dfs(int start, int end) {
        int i;
        if (start == end) {
            for (i = 0; i <= end; i++) {
                System.out.print(nums[i]);
            }
            System.out.println();
        }

        else
            for (i = start; i <= end; i++) {
                swap(nums,start,i);
                dfs(start + 1, end);
                swap(nums,start,i);
            }

    }

    private static void swap(int[] nums,int a, int b) {
        int tmp = nums[a];
        nums[a] = nums[b];
        nums[b] = tmp;
    }
}
